package com.shengzai.mapreduce.studentjoin;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MapStudentJoin extends Mapper<LongWritable, Text,Text,Text> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        String lines =value.toString();
        if(lines.contains(",")){
            String[] split = lines.split(",");
            String sID = split[0];
            String info = split[1]+","+split[2]+","+split[3]+","+split[4];
            context.write(new Text(sID),new Text(info));
        }else{
            String[] splits = lines.split("\t");
            String sId = splits[0];
            String score = splits[1];
            context.write(new Text(sId),new Text(score));
        }
    }
}
